import dataApi from '@/api/data.js'
import { MergeBillApi } from '@/api/MergeBill.api.js'
import { Common } from '@/utils/common.js'
import config from '@/config'
const baseUrl = process.env.NODE_ENV === 'development' ? config.baseUrl.dev : config.baseUrl.pro.replace('/api', '/')

export default {
  name: '',

  data () {
    return {
      isShowTableHuizongbaobiaoModal: false,
      companyName: null,
      companyId: null,
      year: null,
      month: null,
      remark: null,
      billDate: null,
      tableData: [],
      newTableData: [],
      tableComone: {
        pageIndex: 1, // 页码
        totalRows: 0, // 总条数
        pageSize: 10 // 当前页面展示条数
      },
      payDeadLineDay: '',
      banks: [],
      byActually: 'true',
      arrListDown: {
        byActuallyOps: [
          { label: '按实发工资显示', value: 'true' },
          { label: '按应发工资显示', value: 'false' }
        ]
      }
    }
  },

  watch: {
  },

  mounted () {
  },

  methods: {
    /**
     * 分页页码变动
     * @param {Number} val pageIndex
     */
    onChangePage (val) {
      this.tableComone.pageIndex = val
      this.query()
    },
    /**
     * 分页页码变动
     * @param {Number} val pageSize
     */
    onpageSizeChange (val) {
      this.tableComone.pageIndex = 1
      this.tableComone.pageSize = val
      this.query()
    },
    /**
     * 分页查询接口
     * @param {Object} obj {pageIndex, pageSize}
     */
    async query () {
      var params = {
        CompanyIds: this.companyId.join(','),
        Category: 0,
        Month: this.billDate,
        IgnoreInsureNo: this.ignoreInsureNo,
        HasPaging: true,
        PageIndex: this.tableComone.pageIndex,
        PageSize: this.tableComone.pageSize,
        ByActually: this.byActually,
      }
      let res = await MergeBillApi.getSummaryList(params)
      console.log('汇总报表res: ', res)
      if (res.status === 200 && res.data.success) {
        this.remark = res.data.message
        var tempTable = []
        res.data.data.map((item, idx) => {
          console.log('item: ', item)
          if (item.canShow) {
            tempTable.push({...{typeName: item.typeName, ...item.amount}})
          }
        })
        this.newTableData = tempTable
      } else {
        this.newTableData = []
        this.$Message.error({
          content: res.data.message,
          duration: 10,
          closable: true
        })
      }
      this.loading = false
    },

    // 获取银行账户信息
    // async customerPayInfo () {
    //   dataApi.customerPayInfo({id: this.companyId}).then(res => {
    //     console.log('获取银行账户信息res: ', res)
    //     if (res.status === 200 && res.data.success) {
    //       this.payDeadLineDay = res.data.data.payDeadLineDay
    //       this.banks = res.data.data.banks
    //     }
    //   })
    // },

    ok () {
    },

    cancel () {
    },

    handleExportData () {
    },

    parsingItems (row, item, oneTitle, twoTitle1, twoTitle2, type) {
      var sumTitle = oneTitle + twoTitle1 + type
      console.log('sumTitle: ', sumTitle)
      row[sumTitle] = item[twoTitle1][type]
    },

    // 汇总报表导出
    async exportSummaryList () {
      var params = {
        CompanyIds: this.companyId.join(','),
        Category: 0,
        Month: this.billDate,
        IgnoreInsureNo: this.ignoreInsureNo,
        HasPaging: true,
        PageIndex: this.tableComone.pageIndex,
        PageSize: this.tableComone.pageSize,
        ByActually: this.byActually,
      }
      console.log('导出params: ', params)
      let res = await MergeBillApi.exportSummaryList(params)
      if (res.status === 200 && res.data.success) {
        console.log('❤ 返回链接: ', baseUrl + res.data.data)
        window.open(baseUrl + res.data.data, '_blank')
      } else {
        this.$Message.error({
          content: res.data.message,
          duration: 10,
          closable: true
        })
      }
    },

    // 汇总报表导出PDF
    async exportSummaryListPdf () {
      var params = {
        CompanyIds: this.companyId.join(','),
        Category: 0,
        Month: this.billDate,
        IgnoreInsureNo: this.ignoreInsureNo,
        HasPaging: true,
        PageIndex: this.tableComone.pageIndex,
        PageSize: this.tableComone.pageSize,
        ByActually: this.byActually,
      }
      console.log('汇总报表导出params: ', params)
      let res = await MergeBillApi.exportSummaryListPdf(params)
      if (res.status === 200 && res.data.success) {
        console.log('❤ 返回链接: ', baseUrl + res.data.data)
        window.open(baseUrl + res.data.data, '_blank')
      } else {
        this.$Message.error({
          content: res.data.message,
          duration: 10,
          closable: true
        })
      }
    },

    // 显示方式改变
    handleByActuallyChange (byActually) {
      console.log('byActually: ', byActually)
      this.query()
    }
  }
}
